<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/layers/window_data_layer.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../../index.html">top level</a> - <a href="index.html">src/caffe/layers</a> - window_data_layer.cpp<span style="font-size: 80%;"> (source / <a href="window_data_layer.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">198</td>
            <td class="headerCovTableEntryLo">1.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">2</td>
            <td class="headerCovTableEntry">14</td>
            <td class="headerCovTableEntryLo">14.3 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifdef USE_OPENCV</a>
<span class="lineNum">       2 </span>            : #include &lt;opencv2/highgui/highgui_c.h&gt;
<span class="lineNum">       3 </span>            : #include &lt;stdint.h&gt;
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : #include &lt;algorithm&gt;
<span class="lineNum">       6 </span>            : #include &lt;map&gt;
<span class="lineNum">       7 </span>            : #include &lt;string&gt;
<span class="lineNum">       8 </span>            : #include &lt;utility&gt;
<span class="lineNum">       9 </span>            : #include &lt;vector&gt;
<span class="lineNum">      10 </span>            : 
<span class="lineNum">      11 </span>            : #include &quot;opencv2/core/core.hpp&quot;
<span class="lineNum">      12 </span>            : #include &quot;opencv2/highgui/highgui.hpp&quot;
<span class="lineNum">      13 </span>            : #include &quot;opencv2/imgproc/imgproc.hpp&quot;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;caffe/data_transformer.hpp&quot;
<span class="lineNum">      16 </span>            : #include &quot;caffe/internal_thread.hpp&quot;
<span class="lineNum">      17 </span>            : #include &quot;caffe/layers/base_data_layer.hpp&quot;
<span class="lineNum">      18 </span>            : #include &quot;caffe/layers/window_data_layer.hpp&quot;
<span class="lineNum">      19 </span>            : #include &quot;caffe/util/benchmark.hpp&quot;
<span class="lineNum">      20 </span>            : #include &quot;caffe/util/io.hpp&quot;
<span class="lineNum">      21 </span>            : #include &quot;caffe/util/math_functions.hpp&quot;
<span class="lineNum">      22 </span>            : #include &quot;caffe/util/rng.hpp&quot;
<span class="lineNum">      23 </span>            : 
<span class="lineNum">      24 </span>            : // caffe.proto &gt; LayerParameter &gt; WindowDataParameter
<span class="lineNum">      25 </span>            : //   'source' field specifies the window_file
<span class="lineNum">      26 </span>            : //   'crop_size' indicates the desired warped size
<span class="lineNum">      27 </span>            : 
<span class="lineNum">      28 </span>            : namespace caffe {
<a name="29"><span class="lineNum">      29 </span>            : </a>
<span class="lineNum">      30 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      31 </span><span class="lineNoCov">          0 : WindowDataLayer&lt;Dtype&gt;::~WindowDataLayer&lt;Dtype&gt;() {</span>
<span class="lineNum">      32 </span><span class="lineNoCov">          0 :   this-&gt;StopInternalThread();</span>
<span class="lineNum">      33 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">      34 </span>            : 
<span class="lineNum">      35 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">      36 </span><span class="lineNoCov">          0 : void WindowDataLayer&lt;Dtype&gt;::DataLayerSetUp(const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; bottom,</span>
<span class="lineNum">      37 </span>            :       const vector&lt;Blob&lt;Dtype&gt;*&gt;&amp; top) {
<span class="lineNum">      38 </span>            :   // LayerSetUp runs through the window_file and creates two structures
<span class="lineNum">      39 </span>            :   // that hold windows: one for foreground (object) windows and one
<span class="lineNum">      40 </span>            :   // for background (non-object) windows. We use an overlap threshold
<span class="lineNum">      41 </span>            :   // to decide which is which.
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            :   // window_file format
<span class="lineNum">      44 </span>            :   // repeated:
<span class="lineNum">      45 </span>            :   //    # image_index
<span class="lineNum">      46 </span>            :   //    img_path (abs path)
<span class="lineNum">      47 </span>            :   //    channels
<span class="lineNum">      48 </span>            :   //    height
<span class="lineNum">      49 </span>            :   //    width
<span class="lineNum">      50 </span>            :   //    num_windows
<span class="lineNum">      51 </span>            :   //    class_index overlap x1 y1 x2 y2
<span class="lineNum">      52 </span>            : 
<span class="lineNum">      53 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;Window data layer:&quot; &lt;&lt; std::endl</span>
<span class="lineNum">      54 </span>            :       &lt;&lt; &quot;  foreground (object) overlap threshold: &quot;
<span class="lineNum">      55 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().fg_threshold() &lt;&lt; std::endl
<span class="lineNum">      56 </span>            :       &lt;&lt; &quot;  background (non-object) overlap threshold: &quot;
<span class="lineNum">      57 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().bg_threshold() &lt;&lt; std::endl
<span class="lineNum">      58 </span>            :       &lt;&lt; &quot;  foreground sampling fraction: &quot;
<span class="lineNum">      59 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().fg_fraction() &lt;&lt; std::endl
<span class="lineNum">      60 </span>            :       &lt;&lt; &quot;  cache_images: &quot;
<span class="lineNum">      61 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().cache_images() &lt;&lt; std::endl
<span class="lineNum">      62 </span>            :       &lt;&lt; &quot;  root_folder: &quot;
<span class="lineNum">      63 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().root_folder();
<span class="lineNum">      64 </span>            : 
<span class="lineNum">      65 </span><span class="lineNoCov">          0 :   cache_images_ = this-&gt;layer_param_.window_data_param().cache_images();</span>
<span class="lineNum">      66 </span>            :   string root_folder = this-&gt;layer_param_.window_data_param().root_folder();
<span class="lineNum">      67 </span>            : 
<span class="lineNum">      68 </span>            :   const bool prefetch_needs_rand =
<span class="lineNum">      69 </span>            :       this-&gt;transform_param_.mirror() ||
<span class="lineNum">      70 </span><span class="lineNoCov">          0 :       this-&gt;transform_param_.crop_size();</span>
<span class="lineNum">      71 </span><span class="lineNoCov">          0 :   if (prefetch_needs_rand) {</span>
<span class="lineNum">      72 </span><span class="lineNoCov">          0 :     const unsigned int prefetch_rng_seed = caffe_rng_rand();</span>
<span class="lineNum">      73 </span><span class="lineNoCov">          0 :     prefetch_rng_.reset(new Caffe::RNG(prefetch_rng_seed));</span>
<span class="lineNum">      74 </span>            :   } else {
<span class="lineNum">      75 </span>            :     prefetch_rng_.reset();
<span class="lineNum">      76 </span>            :   }
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span><span class="lineNoCov">          0 :   std::ifstream infile(this-&gt;layer_param_.window_data_param().source().c_str());</span>
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :   CHECK(infile.good()) &lt;&lt; &quot;Failed to open window file &quot;</span>
<span class="lineNum">      80 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().source() &lt;&lt; std::endl;
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span>            :   map&lt;int, int&gt; label_hist;
<span class="lineNum">      83 </span><span class="lineNoCov">          0 :   label_hist.insert(std::make_pair(0, 0));</span>
<span class="lineNum">      84 </span>            : 
<span class="lineNum">      85 </span>            :   string hashtag;
<span class="lineNum">      86 </span>            :   int image_index, channels;
<span class="lineNum">      87 </span><span class="lineNoCov">          0 :   if (!(infile &gt;&gt; hashtag &gt;&gt; image_index)) {</span>
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :     LOG(FATAL) &lt;&lt; &quot;Window file is empty&quot;;</span>
<span class="lineNum">      89 </span>            :   }
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :   do {</span>
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :     CHECK_EQ(hashtag, &quot;#&quot;);</span>
<span class="lineNum">      92 </span>            :     // read image path
<span class="lineNum">      93 </span>            :     string image_path;
<span class="lineNum">      94 </span><span class="lineNoCov">          0 :     infile &gt;&gt; image_path;</span>
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :     image_path = root_folder + image_path;</span>
<span class="lineNum">      96 </span>            :     // read image dimensions
<span class="lineNum">      97 </span><span class="lineNoCov">          0 :     vector&lt;int&gt; image_size(3);</span>
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :     infile &gt;&gt; image_size[0] &gt;&gt; image_size[1] &gt;&gt; image_size[2];</span>
<span class="lineNum">      99 </span><span class="lineNoCov">          0 :     channels = image_size[0];</span>
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :     image_database_.push_back(std::make_pair(image_path, image_size));</span>
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :     if (cache_images_) {</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :       Datum datum;</span>
<span class="lineNum">     104 </span><span class="lineNoCov">          0 :       if (!ReadFileToDatum(image_path, &amp;datum)) {</span>
<span class="lineNum">     105 </span><span class="lineNoCov">          0 :         LOG(ERROR) &lt;&lt; &quot;Could not open or find file &quot; &lt;&lt; image_path;</span>
<span class="lineNum">     106 </span><span class="lineNoCov">          0 :         return;</span>
<span class="lineNum">     107 </span>            :       }
<span class="lineNum">     108 </span><span class="lineNoCov">          0 :       image_database_cache_.push_back(std::make_pair(image_path, datum));</span>
<span class="lineNum">     109 </span>            :     }
<span class="lineNum">     110 </span>            :     // read each box
<span class="lineNum">     111 </span>            :     int num_windows;
<span class="lineNum">     112 </span><span class="lineNoCov">          0 :     infile &gt;&gt; num_windows;</span>
<span class="lineNum">     113 </span>            :     const float fg_threshold =
<span class="lineNum">     114 </span>            :         this-&gt;layer_param_.window_data_param().fg_threshold();
<span class="lineNum">     115 </span>            :     const float bg_threshold =
<span class="lineNum">     116 </span>            :         this-&gt;layer_param_.window_data_param().bg_threshold();
<span class="lineNum">     117 </span><span class="lineNoCov">          0 :     for (int i = 0; i &lt; num_windows; ++i) {</span>
<span class="lineNum">     118 </span>            :       int label, x1, y1, x2, y2;
<span class="lineNum">     119 </span>            :       float overlap;
<span class="lineNum">     120 </span><span class="lineNoCov">          0 :       infile &gt;&gt; label &gt;&gt; overlap &gt;&gt; x1 &gt;&gt; y1 &gt;&gt; x2 &gt;&gt; y2;</span>
<span class="lineNum">     121 </span>            : 
<span class="lineNum">     122 </span><span class="lineNoCov">          0 :       vector&lt;float&gt; window(WindowDataLayer::NUM);</span>
<span class="lineNum">     123 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::IMAGE_INDEX] = image_index;</span>
<span class="lineNum">     124 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::LABEL] = label;</span>
<span class="lineNum">     125 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::OVERLAP] = overlap;</span>
<span class="lineNum">     126 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::X1] = x1;</span>
<span class="lineNum">     127 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::Y1] = y1;</span>
<span class="lineNum">     128 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::X2] = x2;</span>
<span class="lineNum">     129 </span><span class="lineNoCov">          0 :       window[WindowDataLayer::Y2] = y2;</span>
<span class="lineNum">     130 </span>            : 
<span class="lineNum">     131 </span>            :       // add window to foreground list or background list
<span class="lineNum">     132 </span><span class="lineNoCov">          0 :       if (overlap &gt;= fg_threshold) {</span>
<span class="lineNum">     133 </span><span class="lineNoCov">          0 :         int label = window[WindowDataLayer::LABEL];</span>
<span class="lineNum">     134 </span><span class="lineNoCov">          0 :         CHECK_GT(label, 0);</span>
<span class="lineNum">     135 </span><span class="lineNoCov">          0 :         fg_windows_.push_back(window);</span>
<span class="lineNum">     136 </span><span class="lineNoCov">          0 :         label_hist.insert(std::make_pair(label, 0));</span>
<span class="lineNum">     137 </span><span class="lineNoCov">          0 :         label_hist[label]++;</span>
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :       } else if (overlap &lt; bg_threshold) {</span>
<span class="lineNum">     139 </span>            :         // background window, force label and overlap to 0
<span class="lineNum">     140 </span><span class="lineNoCov">          0 :         window[WindowDataLayer::LABEL] = 0;</span>
<span class="lineNum">     141 </span><span class="lineNoCov">          0 :         window[WindowDataLayer::OVERLAP] = 0;</span>
<span class="lineNum">     142 </span><span class="lineNoCov">          0 :         bg_windows_.push_back(window);</span>
<span class="lineNum">     143 </span><span class="lineNoCov">          0 :         label_hist[0]++;</span>
<span class="lineNum">     144 </span>            :       }
<span class="lineNum">     145 </span>            :     }
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span><span class="lineNoCov">          0 :     if (image_index % 100 == 0) {</span>
<span class="lineNum">     148 </span><span class="lineNoCov">          0 :       LOG(INFO) &lt;&lt; &quot;num: &quot; &lt;&lt; image_index &lt;&lt; &quot; &quot;</span>
<span class="lineNum">     149 </span>            :           &lt;&lt; image_path &lt;&lt; &quot; &quot;
<span class="lineNum">     150 </span><span class="lineNoCov">          0 :           &lt;&lt; image_size[0] &lt;&lt; &quot; &quot;</span>
<span class="lineNum">     151 </span><span class="lineNoCov">          0 :           &lt;&lt; image_size[1] &lt;&lt; &quot; &quot;</span>
<span class="lineNum">     152 </span><span class="lineNoCov">          0 :           &lt;&lt; image_size[2] &lt;&lt; &quot; &quot;</span>
<span class="lineNum">     153 </span>            :           &lt;&lt; &quot;windows to process: &quot; &lt;&lt; num_windows;
<span class="lineNum">     154 </span>            :     }
<span class="lineNum">     155 </span><span class="lineNoCov">          0 :   } while (infile &gt;&gt; hashtag &gt;&gt; image_index);</span>
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;Number of images: &quot; &lt;&lt; image_index+1;</span>
<span class="lineNum">     158 </span>            : 
<span class="lineNum">     159 </span><span class="lineNoCov">          0 :   for (map&lt;int, int&gt;::iterator it = label_hist.begin();</span>
<span class="lineNum">     160 </span>            :       it != label_hist.end(); ++it) {
<span class="lineNum">     161 </span><span class="lineNoCov">          0 :     LOG(INFO) &lt;&lt; &quot;class &quot; &lt;&lt; it-&gt;first &lt;&lt; &quot; has &quot; &lt;&lt; label_hist[it-&gt;first]</span>
<span class="lineNum">     162 </span>            :               &lt;&lt; &quot; samples&quot;;
<span class="lineNum">     163 </span>            :   }
<span class="lineNum">     164 </span>            : 
<span class="lineNum">     165 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;Amount of context padding: &quot;</span>
<span class="lineNum">     166 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().context_pad();
<span class="lineNum">     167 </span>            : 
<span class="lineNum">     168 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;Crop mode: &quot;</span>
<span class="lineNum">     169 </span>            :       &lt;&lt; this-&gt;layer_param_.window_data_param().crop_mode();
<span class="lineNum">     170 </span>            : 
<span class="lineNum">     171 </span>            :   // image
<span class="lineNum">     172 </span><span class="lineNoCov">          0 :   const int crop_size = this-&gt;transform_param_.crop_size();</span>
<span class="lineNum">     173 </span><span class="lineNoCov">          0 :   CHECK_GT(crop_size, 0);</span>
<span class="lineNum">     174 </span><span class="lineNoCov">          0 :   const int batch_size = this-&gt;layer_param_.window_data_param().batch_size();</span>
<span class="lineNum">     175 </span><span class="lineNoCov">          0 :   top[0]-&gt;Reshape(batch_size, channels, crop_size, crop_size);</span>
<span class="lineNum">     176 </span><span class="lineNoCov">          0 :   for (int i = 0; i &lt; this-&gt;prefetch_.size(); ++i)</span>
<span class="lineNum">     177 </span><span class="lineNoCov">          0 :     this-&gt;prefetch_[i]-&gt;data_.Reshape(</span>
<span class="lineNum">     178 </span>            :         batch_size, channels, crop_size, crop_size);
<span class="lineNum">     179 </span>            : 
<span class="lineNum">     180 </span><span class="lineNoCov">          0 :   LOG(INFO) &lt;&lt; &quot;output data size: &quot; &lt;&lt; top[0]-&gt;num() &lt;&lt; &quot;,&quot;</span>
<span class="lineNum">     181 </span><span class="lineNoCov">          0 :       &lt;&lt; top[0]-&gt;channels() &lt;&lt; &quot;,&quot; &lt;&lt; top[0]-&gt;height() &lt;&lt; &quot;,&quot;</span>
<span class="lineNum">     182 </span><span class="lineNoCov">          0 :       &lt;&lt; top[0]-&gt;width();</span>
<span class="lineNum">     183 </span>            :   // label
<span class="lineNum">     184 </span><span class="lineNoCov">          0 :   vector&lt;int&gt; label_shape(1, batch_size);</span>
<span class="lineNum">     185 </span><span class="lineNoCov">          0 :   top[1]-&gt;Reshape(label_shape);</span>
<span class="lineNum">     186 </span><span class="lineNoCov">          0 :   for (int i = 0; i &lt; this-&gt;prefetch_.size(); ++i) {</span>
<span class="lineNum">     187 </span><span class="lineNoCov">          0 :     this-&gt;prefetch_[i]-&gt;label_.Reshape(label_shape);</span>
<span class="lineNum">     188 </span>            :   }
<span class="lineNum">     189 </span>            : 
<span class="lineNum">     190 </span>            :   // data mean
<span class="lineNum">     191 </span><span class="lineNoCov">          0 :   has_mean_file_ = this-&gt;transform_param_.has_mean_file();</span>
<span class="lineNum">     192 </span><span class="lineNoCov">          0 :   has_mean_values_ = this-&gt;transform_param_.mean_value_size() &gt; 0;</span>
<span class="lineNum">     193 </span><span class="lineNoCov">          0 :   if (has_mean_file_) {</span>
<span class="lineNum">     194 </span>            :     const string&amp; mean_file =
<span class="lineNum">     195 </span>            :           this-&gt;transform_param_.mean_file();
<span class="lineNum">     196 </span><span class="lineNoCov">          0 :     LOG(INFO) &lt;&lt; &quot;Loading mean file from: &quot; &lt;&lt; mean_file;</span>
<span class="lineNum">     197 </span><span class="lineNoCov">          0 :     BlobProto blob_proto;</span>
<span class="lineNum">     198 </span><span class="lineNoCov">          0 :     ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &amp;blob_proto);</span>
<span class="lineNum">     199 </span><span class="lineNoCov">          0 :     data_mean_.FromProto(blob_proto);</span>
<span class="lineNum">     200 </span>            :   }
<span class="lineNum">     201 </span><span class="lineNoCov">          0 :   if (has_mean_values_) {</span>
<span class="lineNum">     202 </span><span class="lineNoCov">          0 :     CHECK(has_mean_file_ == false) &lt;&lt;</span>
<span class="lineNum">     203 </span>            :       &quot;Cannot specify mean_file and mean_value at the same time&quot;;
<span class="lineNum">     204 </span><span class="lineNoCov">          0 :     for (int c = 0; c &lt; this-&gt;transform_param_.mean_value_size(); ++c) {</span>
<span class="lineNum">     205 </span><span class="lineNoCov">          0 :       mean_values_.push_back(this-&gt;transform_param_.mean_value(c));</span>
<span class="lineNum">     206 </span>            :     }
<span class="lineNum">     207 </span><span class="lineNoCov">          0 :     CHECK(mean_values_.size() == 1 || mean_values_.size() == channels) &lt;&lt;</span>
<span class="lineNum">     208 </span><span class="lineNoCov">          0 :      &quot;Specify either 1 mean_value or as many as channels: &quot; &lt;&lt; channels;</span>
<span class="lineNum">     209 </span><span class="lineNoCov">          0 :     if (channels &gt; 1 &amp;&amp; mean_values_.size() == 1) {</span>
<span class="lineNum">     210 </span>            :       // Replicate the mean_value for simplicity
<span class="lineNum">     211 </span><span class="lineNoCov">          0 :       for (int c = 1; c &lt; channels; ++c) {</span>
<span class="lineNum">     212 </span><span class="lineNoCov">          0 :         mean_values_.push_back(mean_values_[0]);</span>
<span class="lineNum">     213 </span>            :       }
<span class="lineNum">     214 </span>            :     }
<span class="lineNum">     215 </span>            :   }
<span class="lineNum">     216 </span>            : }
<a name="217"><span class="lineNum">     217 </span>            : </a>
<span class="lineNum">     218 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">     219 </span><span class="lineNoCov">          0 : unsigned int WindowDataLayer&lt;Dtype&gt;::PrefetchRand() {</span>
<span class="lineNum">     220 </span><span class="lineNoCov">          0 :   CHECK(prefetch_rng_);</span>
<span class="lineNum">     221 </span>            :   caffe::rng_t* prefetch_rng =
<span class="lineNum">     222 </span><span class="lineNoCov">          0 :       static_cast&lt;caffe::rng_t*&gt;(prefetch_rng_-&gt;generator());</span>
<span class="lineNum">     223 </span><span class="lineNoCov">          0 :   return (*prefetch_rng)();</span>
<span class="lineNum">     224 </span>            : }
<span class="lineNum">     225 </span>            : 
<span class="lineNum">     226 </span>            : // This function is called on prefetch thread
<span class="lineNum">     227 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">     228 </span><span class="lineNoCov">          0 : void WindowDataLayer&lt;Dtype&gt;::load_batch(Batch&lt;Dtype&gt;* batch) {</span>
<span class="lineNum">     229 </span>            :   // At each iteration, sample N windows where N*p are foreground (object)
<span class="lineNum">     230 </span>            :   // windows and N*(1-p) are background (non-object) windows
<span class="lineNum">     231 </span><span class="lineNoCov">          0 :   CPUTimer batch_timer;</span>
<span class="lineNum">     232 </span><span class="lineNoCov">          0 :   batch_timer.Start();</span>
<span class="lineNum">     233 </span>            :   double read_time = 0;
<span class="lineNum">     234 </span>            :   double trans_time = 0;
<span class="lineNum">     235 </span><span class="lineNoCov">          0 :   CPUTimer timer;</span>
<span class="lineNum">     236 </span><span class="lineNoCov">          0 :   Dtype* top_data = batch-&gt;data_.mutable_cpu_data();</span>
<span class="lineNum">     237 </span><span class="lineNoCov">          0 :   Dtype* top_label = batch-&gt;label_.mutable_cpu_data();</span>
<span class="lineNum">     238 </span><span class="lineNoCov">          0 :   const Dtype scale = this-&gt;layer_param_.window_data_param().scale();</span>
<span class="lineNum">     239 </span><span class="lineNoCov">          0 :   const int batch_size = this-&gt;layer_param_.window_data_param().batch_size();</span>
<span class="lineNum">     240 </span><span class="lineNoCov">          0 :   const int context_pad = this-&gt;layer_param_.window_data_param().context_pad();</span>
<span class="lineNum">     241 </span><span class="lineNoCov">          0 :   const int crop_size = this-&gt;transform_param_.crop_size();</span>
<span class="lineNum">     242 </span>            :   const bool mirror = this-&gt;transform_param_.mirror();
<span class="lineNum">     243 </span>            :   const float fg_fraction =
<span class="lineNum">     244 </span>            :       this-&gt;layer_param_.window_data_param().fg_fraction();
<span class="lineNum">     245 </span>            :   Dtype* mean = NULL;
<span class="lineNum">     246 </span>            :   int mean_off = 0;
<span class="lineNum">     247 </span>            :   int mean_width = 0;
<span class="lineNum">     248 </span>            :   int mean_height = 0;
<span class="lineNum">     249 </span><span class="lineNoCov">          0 :   if (this-&gt;has_mean_file_) {</span>
<span class="lineNum">     250 </span><span class="lineNoCov">          0 :     mean = this-&gt;data_mean_.mutable_cpu_data();</span>
<span class="lineNum">     251 </span><span class="lineNoCov">          0 :     mean_off = (this-&gt;data_mean_.width() - crop_size) / 2;</span>
<span class="lineNum">     252 </span>            :     mean_width = this-&gt;data_mean_.width();
<span class="lineNum">     253 </span>            :     mean_height = this-&gt;data_mean_.height();
<span class="lineNum">     254 </span>            :   }
<span class="lineNum">     255 </span>            :   cv::Size cv_crop_size(crop_size, crop_size);
<span class="lineNum">     256 </span>            :   const string&amp; crop_mode = this-&gt;layer_param_.window_data_param().crop_mode();
<span class="lineNum">     257 </span>            : 
<span class="lineNum">     258 </span>            :   bool use_square = (crop_mode == &quot;square&quot;) ? true : false;
<span class="lineNum">     259 </span>            : 
<span class="lineNum">     260 </span>            :   // zero out batch
<span class="lineNum">     261 </span><span class="lineNoCov">          0 :   caffe_set(batch-&gt;data_.count(), Dtype(0), top_data);</span>
<span class="lineNum">     262 </span>            : 
<span class="lineNum">     263 </span>            :   const int num_fg = static_cast&lt;int&gt;(static_cast&lt;float&gt;(batch_size)
<span class="lineNum">     264 </span><span class="lineNoCov">          0 :       * fg_fraction);</span>
<span class="lineNum">     265 </span><span class="lineNoCov">          0 :   const int num_samples[2] = { batch_size - num_fg, num_fg };</span>
<span class="lineNum">     266 </span>            : 
<span class="lineNum">     267 </span>            :   int item_id = 0;
<span class="lineNum">     268 </span><span class="lineNoCov">          0 :   CHECK_GT(fg_windows_.size(), 0);</span>
<span class="lineNum">     269 </span><span class="lineNoCov">          0 :   CHECK_GT(bg_windows_.size(), 0);</span>
<span class="lineNum">     270 </span>            : 
<span class="lineNum">     271 </span>            :   // sample from bg set then fg set
<span class="lineNum">     272 </span><span class="lineNoCov">          0 :   for (int is_fg = 0; is_fg &lt; 2; ++is_fg) {</span>
<span class="lineNum">     273 </span><span class="lineNoCov">          0 :     for (int dummy = 0; dummy &lt; num_samples[is_fg]; ++dummy) {</span>
<span class="lineNum">     274 </span>            :       // sample a window
<span class="lineNum">     275 </span><span class="lineNoCov">          0 :       timer.Start();</span>
<span class="lineNum">     276 </span><span class="lineNoCov">          0 :       const unsigned int rand_index = PrefetchRand();</span>
<span class="lineNum">     277 </span>            :       vector&lt;float&gt; window = (is_fg) ?
<span class="lineNum">     278 </span>            :           fg_windows_[rand_index % fg_windows_.size()] :
<span class="lineNum">     279 </span><span class="lineNoCov">          0 :           bg_windows_[rand_index % bg_windows_.size()];</span>
<span class="lineNum">     280 </span>            : 
<span class="lineNum">     281 </span><span class="lineNoCov">          0 :       bool do_mirror = mirror &amp;&amp; PrefetchRand() % 2;</span>
<span class="lineNum">     282 </span>            : 
<span class="lineNum">     283 </span>            :       // load the image containing the window
<span class="lineNum">     284 </span>            :       pair&lt;std::string, vector&lt;int&gt; &gt; image =
<span class="lineNum">     285 </span><span class="lineNoCov">          0 :           image_database_[window[WindowDataLayer&lt;Dtype&gt;::IMAGE_INDEX]];</span>
<span class="lineNum">     286 </span>            : 
<span class="lineNum">     287 </span><span class="lineNoCov">          0 :       cv::Mat cv_img;</span>
<span class="lineNum">     288 </span><span class="lineNoCov">          0 :       if (this-&gt;cache_images_) {</span>
<span class="lineNum">     289 </span>            :         pair&lt;std::string, Datum&gt; image_cached =
<span class="lineNum">     290 </span><span class="lineNoCov">          0 :           image_database_cache_[window[WindowDataLayer&lt;Dtype&gt;::IMAGE_INDEX]];</span>
<span class="lineNum">     291 </span><span class="lineNoCov">          0 :         cv_img = DecodeDatumToCVMat(image_cached.second, true);</span>
<span class="lineNum">     292 </span>            :       } else {
<span class="lineNum">     293 </span><span class="lineNoCov">          0 :         cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);</span>
<span class="lineNum">     294 </span><span class="lineNoCov">          0 :         if (!cv_img.data) {</span>
<span class="lineNum">     295 </span><span class="lineNoCov">          0 :           LOG(ERROR) &lt;&lt; &quot;Could not open or find file &quot; &lt;&lt; image.first;</span>
<span class="lineNum">     296 </span><span class="lineNoCov">          0 :           return;</span>
<span class="lineNum">     297 </span>            :         }
<span class="lineNum">     298 </span>            :       }
<span class="lineNum">     299 </span><span class="lineNoCov">          0 :       read_time += timer.MicroSeconds();</span>
<span class="lineNum">     300 </span><span class="lineNoCov">          0 :       timer.Start();</span>
<span class="lineNum">     301 </span>            :       const int channels = cv_img.channels();
<span class="lineNum">     302 </span>            : 
<span class="lineNum">     303 </span>            :       // crop window out of image and warp it
<span class="lineNum">     304 </span><span class="lineNoCov">          0 :       int x1 = window[WindowDataLayer&lt;Dtype&gt;::X1];</span>
<span class="lineNum">     305 </span><span class="lineNoCov">          0 :       int y1 = window[WindowDataLayer&lt;Dtype&gt;::Y1];</span>
<span class="lineNum">     306 </span><span class="lineNoCov">          0 :       int x2 = window[WindowDataLayer&lt;Dtype&gt;::X2];</span>
<span class="lineNum">     307 </span><span class="lineNoCov">          0 :       int y2 = window[WindowDataLayer&lt;Dtype&gt;::Y2];</span>
<span class="lineNum">     308 </span>            : 
<span class="lineNum">     309 </span>            :       int pad_w = 0;
<span class="lineNum">     310 </span>            :       int pad_h = 0;
<span class="lineNum">     311 </span><span class="lineNoCov">          0 :       if (context_pad &gt; 0 || use_square) {</span>
<span class="lineNum">     312 </span>            :         // scale factor by which to expand the original region
<span class="lineNum">     313 </span>            :         // such that after warping the expanded region to crop_size x crop_size
<span class="lineNum">     314 </span>            :         // there's exactly context_pad amount of padding on each side
<span class="lineNum">     315 </span>            :         Dtype context_scale = static_cast&lt;Dtype&gt;(crop_size) /
<span class="lineNum">     316 </span><span class="lineNoCov">          0 :             static_cast&lt;Dtype&gt;(crop_size - 2*context_pad);</span>
<span class="lineNum">     317 </span>            : 
<span class="lineNum">     318 </span>            :         // compute the expanded region
<span class="lineNum">     319 </span><span class="lineNoCov">          0 :         Dtype half_height = static_cast&lt;Dtype&gt;(y2-y1+1)/2.0;</span>
<span class="lineNum">     320 </span><span class="lineNoCov">          0 :         Dtype half_width = static_cast&lt;Dtype&gt;(x2-x1+1)/2.0;</span>
<span class="lineNum">     321 </span><span class="lineNoCov">          0 :         Dtype center_x = static_cast&lt;Dtype&gt;(x1) + half_width;</span>
<span class="lineNum">     322 </span><span class="lineNoCov">          0 :         Dtype center_y = static_cast&lt;Dtype&gt;(y1) + half_height;</span>
<span class="lineNum">     323 </span><span class="lineNoCov">          0 :         if (use_square) {</span>
<span class="lineNum">     324 </span><span class="lineNoCov">          0 :           if (half_height &gt; half_width) {</span>
<span class="lineNum">     325 </span>            :             half_width = half_height;
<span class="lineNum">     326 </span>            :           } else {
<span class="lineNum">     327 </span>            :             half_height = half_width;
<span class="lineNum">     328 </span>            :           }
<span class="lineNum">     329 </span>            :         }
<span class="lineNum">     330 </span><span class="lineNoCov">          0 :         x1 = static_cast&lt;int&gt;(round(center_x - half_width*context_scale));</span>
<span class="lineNum">     331 </span><span class="lineNoCov">          0 :         x2 = static_cast&lt;int&gt;(round(center_x + half_width*context_scale));</span>
<span class="lineNum">     332 </span><span class="lineNoCov">          0 :         y1 = static_cast&lt;int&gt;(round(center_y - half_height*context_scale));</span>
<span class="lineNum">     333 </span><span class="lineNoCov">          0 :         y2 = static_cast&lt;int&gt;(round(center_y + half_height*context_scale));</span>
<span class="lineNum">     334 </span>            : 
<span class="lineNum">     335 </span>            :         // the expanded region may go outside of the image
<span class="lineNum">     336 </span>            :         // so we compute the clipped (expanded) region and keep track of
<span class="lineNum">     337 </span>            :         // the extent beyond the image
<span class="lineNum">     338 </span><span class="lineNoCov">          0 :         int unclipped_height = y2-y1+1;</span>
<span class="lineNum">     339 </span><span class="lineNoCov">          0 :         int unclipped_width = x2-x1+1;</span>
<span class="lineNum">     340 </span><span class="lineNoCov">          0 :         int pad_x1 = std::max(0, -x1);</span>
<span class="lineNum">     341 </span><span class="lineNoCov">          0 :         int pad_y1 = std::max(0, -y1);</span>
<span class="lineNum">     342 </span><span class="lineNoCov">          0 :         int pad_x2 = std::max(0, x2 - cv_img.cols + 1);</span>
<span class="lineNum">     343 </span><span class="lineNoCov">          0 :         int pad_y2 = std::max(0, y2 - cv_img.rows + 1);</span>
<span class="lineNum">     344 </span>            :         // clip bounds
<span class="lineNum">     345 </span><span class="lineNoCov">          0 :         x1 = x1 + pad_x1;</span>
<span class="lineNum">     346 </span><span class="lineNoCov">          0 :         x2 = x2 - pad_x2;</span>
<span class="lineNum">     347 </span><span class="lineNoCov">          0 :         y1 = y1 + pad_y1;</span>
<span class="lineNum">     348 </span><span class="lineNoCov">          0 :         y2 = y2 - pad_y2;</span>
<span class="lineNum">     349 </span><span class="lineNoCov">          0 :         CHECK_GT(x1, -1);</span>
<span class="lineNum">     350 </span><span class="lineNoCov">          0 :         CHECK_GT(y1, -1);</span>
<span class="lineNum">     351 </span><span class="lineNoCov">          0 :         CHECK_LT(x2, cv_img.cols);</span>
<span class="lineNum">     352 </span><span class="lineNoCov">          0 :         CHECK_LT(y2, cv_img.rows);</span>
<span class="lineNum">     353 </span>            : 
<span class="lineNum">     354 </span><span class="lineNoCov">          0 :         int clipped_height = y2-y1+1;</span>
<span class="lineNum">     355 </span><span class="lineNoCov">          0 :         int clipped_width = x2-x1+1;</span>
<span class="lineNum">     356 </span>            : 
<span class="lineNum">     357 </span>            :         // scale factors that would be used to warp the unclipped
<span class="lineNum">     358 </span>            :         // expanded region
<span class="lineNum">     359 </span>            :         Dtype scale_x =
<span class="lineNum">     360 </span><span class="lineNoCov">          0 :             static_cast&lt;Dtype&gt;(crop_size)/static_cast&lt;Dtype&gt;(unclipped_width);</span>
<span class="lineNum">     361 </span>            :         Dtype scale_y =
<span class="lineNum">     362 </span><span class="lineNoCov">          0 :             static_cast&lt;Dtype&gt;(crop_size)/static_cast&lt;Dtype&gt;(unclipped_height);</span>
<span class="lineNum">     363 </span>            : 
<span class="lineNum">     364 </span>            :         // size to warp the clipped expanded region to
<span class="lineNum">     365 </span><span class="lineNoCov">          0 :         cv_crop_size.width =</span>
<span class="lineNum">     366 </span><span class="lineNoCov">          0 :             static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(clipped_width)*scale_x));</span>
<span class="lineNum">     367 </span><span class="lineNoCov">          0 :         cv_crop_size.height =</span>
<span class="lineNum">     368 </span><span class="lineNoCov">          0 :             static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(clipped_height)*scale_y));</span>
<span class="lineNum">     369 </span><span class="lineNoCov">          0 :         pad_x1 = static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(pad_x1)*scale_x));</span>
<span class="lineNum">     370 </span><span class="lineNoCov">          0 :         pad_x2 = static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(pad_x2)*scale_x));</span>
<span class="lineNum">     371 </span><span class="lineNoCov">          0 :         pad_y1 = static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(pad_y1)*scale_y));</span>
<span class="lineNum">     372 </span>            :         pad_y2 = static_cast&lt;int&gt;(round(static_cast&lt;Dtype&gt;(pad_y2)*scale_y));
<span class="lineNum">     373 </span>            : 
<span class="lineNum">     374 </span>            :         pad_h = pad_y1;
<span class="lineNum">     375 </span>            :         // if we're mirroring, we mirror the padding too (to be pedantic)
<span class="lineNum">     376 </span><span class="lineNoCov">          0 :         if (do_mirror) {</span>
<span class="lineNum">     377 </span>            :           pad_w = pad_x2;
<span class="lineNum">     378 </span>            :         } else {
<span class="lineNum">     379 </span>            :           pad_w = pad_x1;
<span class="lineNum">     380 </span>            :         }
<span class="lineNum">     381 </span>            : 
<span class="lineNum">     382 </span>            :         // ensure that the warped, clipped region plus the padding fits in the
<span class="lineNum">     383 </span>            :         // crop_size x crop_size image (it might not due to rounding)
<span class="lineNum">     384 </span><span class="lineNoCov">          0 :         if (pad_h + cv_crop_size.height &gt; crop_size) {</span>
<span class="lineNum">     385 </span><span class="lineNoCov">          0 :           cv_crop_size.height = crop_size - pad_h;</span>
<span class="lineNum">     386 </span>            :         }
<span class="lineNum">     387 </span><span class="lineNoCov">          0 :         if (pad_w + cv_crop_size.width &gt; crop_size) {</span>
<span class="lineNum">     388 </span><span class="lineNoCov">          0 :           cv_crop_size.width = crop_size - pad_w;</span>
<span class="lineNum">     389 </span>            :         }
<span class="lineNum">     390 </span>            :       }
<span class="lineNum">     391 </span>            : 
<span class="lineNum">     392 </span><span class="lineNoCov">          0 :       cv::Rect roi(x1, y1, x2-x1+1, y2-y1+1);</span>
<span class="lineNum">     393 </span><span class="lineNoCov">          0 :       cv::Mat cv_cropped_img = cv_img(roi);</span>
<span class="lineNum">     394 </span><span class="lineNoCov">          0 :       cv::resize(cv_cropped_img, cv_cropped_img,</span>
<span class="lineNum">     395 </span>            :           cv_crop_size, 0, 0, cv::INTER_LINEAR);
<span class="lineNum">     396 </span>            : 
<span class="lineNum">     397 </span>            :       // horizontal flip at random
<span class="lineNum">     398 </span><span class="lineNoCov">          0 :       if (do_mirror) {</span>
<span class="lineNum">     399 </span><span class="lineNoCov">          0 :         cv::flip(cv_cropped_img, cv_cropped_img, 1);</span>
<span class="lineNum">     400 </span>            :       }
<span class="lineNum">     401 </span>            : 
<span class="lineNum">     402 </span>            :       // copy the warped window into top_data
<span class="lineNum">     403 </span><span class="lineNoCov">          0 :       for (int h = 0; h &lt; cv_cropped_img.rows; ++h) {</span>
<span class="lineNum">     404 </span>            :         const uchar* ptr = cv_cropped_img.ptr&lt;uchar&gt;(h);
<span class="lineNum">     405 </span>            :         int img_index = 0;
<span class="lineNum">     406 </span><span class="lineNoCov">          0 :         for (int w = 0; w &lt; cv_cropped_img.cols; ++w) {</span>
<span class="lineNum">     407 </span><span class="lineNoCov">          0 :           for (int c = 0; c &lt; channels; ++c) {</span>
<span class="lineNum">     408 </span>            :             int top_index = ((item_id * channels + c) * crop_size + h + pad_h)
<span class="lineNum">     409 </span><span class="lineNoCov">          0 :                      * crop_size + w + pad_w;</span>
<span class="lineNum">     410 </span>            :             // int top_index = (c * height + h) * width + w;
<span class="lineNum">     411 </span><span class="lineNoCov">          0 :             Dtype pixel = static_cast&lt;Dtype&gt;(ptr[img_index++]);</span>
<span class="lineNum">     412 </span><span class="lineNoCov">          0 :             if (this-&gt;has_mean_file_) {</span>
<span class="lineNum">     413 </span>            :               int mean_index = (c * mean_height + h + mean_off + pad_h)
<span class="lineNum">     414 </span><span class="lineNoCov">          0 :                            * mean_width + w + mean_off + pad_w;</span>
<span class="lineNum">     415 </span><span class="lineNoCov">          0 :               top_data[top_index] = (pixel - mean[mean_index]) * scale;</span>
<span class="lineNum">     416 </span>            :             } else {
<span class="lineNum">     417 </span><span class="lineNoCov">          0 :               if (this-&gt;has_mean_values_) {</span>
<span class="lineNum">     418 </span><span class="lineNoCov">          0 :                 top_data[top_index] = (pixel - this-&gt;mean_values_[c]) * scale;</span>
<span class="lineNum">     419 </span>            :               } else {
<span class="lineNum">     420 </span><span class="lineNoCov">          0 :                 top_data[top_index] = pixel * scale;</span>
<span class="lineNum">     421 </span>            :               }
<span class="lineNum">     422 </span>            :             }
<span class="lineNum">     423 </span>            :           }
<span class="lineNum">     424 </span>            :         }
<span class="lineNum">     425 </span>            :       }
<span class="lineNum">     426 </span><span class="lineNoCov">          0 :       trans_time += timer.MicroSeconds();</span>
<span class="lineNum">     427 </span>            :       // get window label
<span class="lineNum">     428 </span><span class="lineNoCov">          0 :       top_label[item_id] = window[WindowDataLayer&lt;Dtype&gt;::LABEL];</span>
<span class="lineNum">     429 </span>            : 
<span class="lineNum">     430 </span>            :       #if 0
<span class="lineNum">     431 </span>            :       // useful debugging code for dumping transformed windows to disk
<span class="lineNum">     432 </span>            :       string file_id;
<span class="lineNum">     433 </span>            :       std::stringstream ss;
<span class="lineNum">     434 </span>            :       ss &lt;&lt; PrefetchRand();
<span class="lineNum">     435 </span>            :       ss &gt;&gt; file_id;
<span class="lineNum">     436 </span>            :       std::ofstream inf((string(&quot;dump/&quot;) + file_id +
<span class="lineNum">     437 </span>            :           string(&quot;_info.txt&quot;)).c_str(), std::ofstream::out);
<span class="lineNum">     438 </span>            :       inf &lt;&lt; image.first &lt;&lt; std::endl
<span class="lineNum">     439 </span>            :           &lt;&lt; window[WindowDataLayer&lt;Dtype&gt;::X1]+1 &lt;&lt; std::endl
<span class="lineNum">     440 </span>            :           &lt;&lt; window[WindowDataLayer&lt;Dtype&gt;::Y1]+1 &lt;&lt; std::endl
<span class="lineNum">     441 </span>            :           &lt;&lt; window[WindowDataLayer&lt;Dtype&gt;::X2]+1 &lt;&lt; std::endl
<span class="lineNum">     442 </span>            :           &lt;&lt; window[WindowDataLayer&lt;Dtype&gt;::Y2]+1 &lt;&lt; std::endl
<span class="lineNum">     443 </span>            :           &lt;&lt; do_mirror &lt;&lt; std::endl
<span class="lineNum">     444 </span>            :           &lt;&lt; top_label[item_id] &lt;&lt; std::endl
<span class="lineNum">     445 </span>            :           &lt;&lt; is_fg &lt;&lt; std::endl;
<span class="lineNum">     446 </span>            :       inf.close();
<span class="lineNum">     447 </span>            :       std::ofstream top_data_file((string(&quot;dump/&quot;) + file_id +
<span class="lineNum">     448 </span>            :           string(&quot;_data.txt&quot;)).c_str(),
<span class="lineNum">     449 </span>            :           std::ofstream::out | std::ofstream::binary);
<span class="lineNum">     450 </span>            :       for (int c = 0; c &lt; channels; ++c) {
<span class="lineNum">     451 </span>            :         for (int h = 0; h &lt; crop_size; ++h) {
<span class="lineNum">     452 </span>            :           for (int w = 0; w &lt; crop_size; ++w) {
<span class="lineNum">     453 </span>            :             top_data_file.write(reinterpret_cast&lt;char*&gt;(
<span class="lineNum">     454 </span>            :                 &amp;top_data[((item_id * channels + c) * crop_size + h)
<span class="lineNum">     455 </span>            :                           * crop_size + w]),
<span class="lineNum">     456 </span>            :                 sizeof(Dtype));
<span class="lineNum">     457 </span>            :           }
<span class="lineNum">     458 </span>            :         }
<span class="lineNum">     459 </span>            :       }
<span class="lineNum">     460 </span>            :       top_data_file.close();
<span class="lineNum">     461 </span>            :       #endif
<span class="lineNum">     462 </span>            : 
<span class="lineNum">     463 </span><span class="lineNoCov">          0 :       item_id++;</span>
<span class="lineNum">     464 </span>            :     }
<span class="lineNum">     465 </span>            :   }
<span class="lineNum">     466 </span><span class="lineNoCov">          0 :   batch_timer.Stop();</span>
<span class="lineNum">     467 </span>            :   DLOG(INFO) &lt;&lt; &quot;Prefetch batch: &quot; &lt;&lt; batch_timer.MilliSeconds() &lt;&lt; &quot; ms.&quot;;
<span class="lineNum">     468 </span>            :   DLOG(INFO) &lt;&lt; &quot;     Read time: &quot; &lt;&lt; read_time / 1000 &lt;&lt; &quot; ms.&quot;;
<span class="lineNum">     469 </span>            :   DLOG(INFO) &lt;&lt; &quot;Transform time: &quot; &lt;&lt; trans_time / 1000 &lt;&lt; &quot; ms.&quot;;
<span class="lineNum">     470 </span>            : }
<a name="471"><span class="lineNum">     471 </span>            : </a>
<span class="lineNum">     472 </span>            : INSTANTIATE_CLASS(WindowDataLayer);
<a name="473"><span class="lineNum">     473 </span><span class="lineCov">          3 : REGISTER_LAYER_CLASS(WindowData);</span></a>
<span class="lineNum">     474 </span>            : 
<span class="lineNum">     475 </span><span class="lineCov">          3 : }  // namespace caffe</span>
<span class="lineNum">     476 </span>            : #endif  // USE_OPENCV
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
